<template>
	<view :style="{ paddingTop: systemInfo.statusBarHeight + systemInfo.titleBarHeight + 'px' }">
		<title-bar :back="true" title="今日生祭"></title-bar>
		<view class="page-content common-page-content" :style="{ minHeight: systemInfo.minHeight }">
			<view class="hall-item today-hall-item first-top" v-for="(item, index) in dataList" :key="item.id" @click="toHallDetail(item.hallId)">
				<view class="hall-info-layout today-hall-info-layout">
					<view class="image-layout today-image-layout">
						<image class="image1" v-if="item.photoUrl" :src="imageUrl + item.photoUrl"></image>
						<image class="image1" v-else src="@/static/image/common/head_default.png"></image>
						<image mode="aspectFill" class="item-bg today-item-bg"></image>
					</view>
					<view class="info-layout today-info-layout">
						<view class="flex-align-center">
							<view class="name-text">{{ item.name }}</view>
							<view class="today-type-text">{{ item.todayType == 0 ? '诞辰' : '忌日' }}</view>
						</view>
						<view class="date-text">{{ dateFormat(item) }}</view>
						<view class="date-text today-death-text">{{ deathFormat(item) }}</view>
					</view>
				</view>
			</view>
			<empty-layout v-if="loadingType === 'empty'" :option="{ tip: '今日无生祭的逝者~' }"></empty-layout>
			<uni-load-more v-if="dataList.length > pageSize" :status="loadingType"></uni-load-more>
		</view>
	</view>
</template>

<script>
import mixin from '@/pages/common/mixins/memorial-hall.js';
import emptyLayout from '@/components/empty-layout/empty-layout.vue';

export default {
	mixins: [mixin],
	components: {
		emptyLayout
	},
	data() {
		return {
			loadingType: 'more',
			pageNum: 1,
			pageSize: 10,
			dataList: []
		};
	},
	methods: {
		/* 跳转纪念馆详情页 */
		toHallDetail(id) {
			uni.navigateTo({
				url: './detail/memorial-hall-detail?id=' + id
			});
		},
		/* 加载今日生祭的逝者 */
		loadData() {
			let param = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				orderByColumn: 'create_time',
				isAsc: 'desc'
			};
			this.$http.get('/deceased/today-list', { params: param }).then(res => {
				if (res.code === 200) {
					if (this.pageNum == 1) {
						this.dataList = [];
					}
					this.dataList = this.dataList.concat(res.rows);
					if (this.dataList.length === 0) {
						this.loadingType = 'empty';
					} else if (this.dataList.length === Number(res.total)) {
						this.loadingType = 'nomore';
					} else {
						this.loadingType = 'more';
					}
				}
			});
		}
	},
	onPullDownRefresh() {
		this.pageNum = 1;
		this.loadingType = 'more';
		this.loadData();
	},
	onReachBottom() {
		if (this.loadingType === 'more') {
			this.pageNum++;
			this.loadingType = 'loading';
			this.loadData();
		}
	},
	onLoad() {
		this.loadData();
	}
};
</script>

<style lang="scss" scoped>
@import './today-memorial-hall.scss';
@import '@/pages/common/css/memorial-hall-item.scss';
</style>
